package org.anjan.dp.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chebbaso on 12/4/14.
 */
public class StockGrabber implements Subject{

    List<Observer> observerList;
    public StockGrabber() {
        observerList = new ArrayList<Observer>();
    }

    @Override
    public void register(Observer observer) {
        observerList.add(observer);

    }

    @Override
    public void deregister(Observer observer) {
        int i = observerList.indexOf(observer);
        i++;
        observerList.remove(i);
    }

    @Override
    public void notifyObservers(String stockPrice, double value) {
        for (Observer observer : observerList) {
            observer.update(stockPrice,  value);
        }
    }


    public void setPrice(String stock, double price)
    {
        notifyObservers(stock, price);
    }
}
